﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.Core.ActionsRadicado
{
    public class Actions
    {

        public void MoveRadicado(string sourceLibrary, string targetLibrary, int radId)
        {            
            SPList source = SPContext.Current.Web.Lists.TryGetList(sourceLibrary); 
            if (source == null)
                throw new Exception(string.Format(ExceptionConstants.ERROR_LISTA_INEXISTENTE, sourceLibrary));
            SPList target = SPContext.Current.Web.Lists.TryGetList(targetLibrary);
            if(target == null)
                throw new Exception(string.Format(ExceptionConstants.ERROR_LISTA_INEXISTENTE, targetLibrary));
            SPListItem currentItem = source.GetItemById(radId);
            SPListItem newItem = target.Items.Add();

            foreach (SPField field in currentItem.Fields)
            { 
                if (!field.ReadOnlyField)
                    newItem[field.Id] = currentItem[field.Id];    
                
            }
            newItem.SystemUpdate();
        }

    }
}
